import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../pages/danger/danger_list2.dart';
import '../../spaces/recordspace/record_list.dart';

import '../../model/security_check.dart';

import 'securitycheck_info.dart';

class SecurityCheckPage extends StatefulWidget {
  @override
  SecurityCheckPage(this.s1);
  final SecurityCheck s1;

  @override
  createState() => new SecurityCheckPageState();
}

class SecurityCheckPageState extends State<SecurityCheckPage> {
//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(
        icon: new Icon(Icons.dashboard), label: ('检查报表')),
    new BottomNavigationBarItem(
        icon: new Icon(Icons.camera_alt), label: ('现场记录')),
    new BottomNavigationBarItem(icon: new Icon(Icons.list), label: ('问题填报')),
  ];

  bool getIfCanAdd() {
    if (widget.s1.State == 2) return false;
    return true;
  }

  Widget getBody(int i) {
    if (i == 0) return SecurityCheckInfoPage(widget.s1, () => {});

    if (i == 1) return RecordListPage(widget.s1.Guid, true);

    if (i == 2) return DangerListPage(false, widget.s1.Guid, getIfCanAdd());
    return new Container();
  }

  final titleList = ["报表", "照片", "视频", "记录"];
  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("安全检查"),
        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: SafeArea(
          top: true,
          child: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              currentIndex: currentIndex,
              items: bottomTabs,
              fixedColor: Colors.blue,
              onTap: (index) {
                setState(() {
                  currentIndex = index;
                  currentPage = getBody(currentIndex);
                });
              })),
      body: SafeArea(top: true, child: currentPage),
    );
  }
}
